Repository navigation
Show every task on the Tasks board, not just the first 100 - #446
abhishekgahlot2 merged 1 commit into
Conversation
GET /api/tasks returned at most 100 tasks in board order (column position, then newest first), with no way to ask for more. New tasks get the highest position, so once a workspace had more than 100 tasks, archived ones included, a new task vanished from the board after a reload and the column counts were short. The list now pages, and the board reads every page: - listTaskPageForOrg (backend/src/tasks/repo.ts) reads one page after a cursor that carries the last task's full sort key: order_key, created_at as whole microseconds, and id. order_key sorts up and the rest down, so "after the cursor" is a later position, or the same position and an older (created_at, id). It reads one row past the limit to know whether another page follows. listTasksForOrg, which the agent's task_list tool uses, keeps its shape on top of it. - GET /api/tasks takes cursor and exclude_archived=1 and answers has_more and next_cursor next to tasks. A malformed cursor answers 400 "cursor is invalid" (backend/src/tasks/page-cursor.ts). Without a cursor the first page is the same as before. - fetchTasks (frontend/app/(library)/tasks/tasks-api.ts) asks for pages of 500 without archived tasks, which have no column, and follows next_cursor to the end. A failed page fails the read, so the board shows its error instead of part of the tasks. A task moved between two pages is shown once, and a repeated cursor stops the loop. An old backend ignores the new parameters and sends no next_cursor, so the new board reads one page as before. An old board ignores the new fields. Docs: the GET /api/tasks row in docs-site/docs/api/skills.mdx.
abhishekgahlot2
left a comment
There was a problem hiding this comment.
Thanks @officialasishkumar, this is a clean change: the cursor is strict with id as the last tiebreak, the after-cursor condition matches the sort, org scoping is tested, and replacing the whole list once per read avoids the boundary race #440/#443 had.
One thing before merging: fetchTasks (tasks-api.ts:28-40) follows next_cursor until it runs out, on every /tasks render and every project-filter change. Each page is capped at 500 but the total isn't, and nothing caps task creation (an agent looping task_create can get there). An org with 20,000 open tasks means 40 sequential requests and 20,000 cards in memory per board load; before this PR the board read at most 100.
Suggested fix: a named page ceiling far past any real board, with truncation reported instead of silent:
/** Board ceiling: 10 pages = 5,000 open tasks, far past any real board. */
const TASKS_MAX_PAGES = 10;
// before each fetch:
if (pages === TASKS_MAX_PAGES) return { tasks: [...tasks.values()], truncated: true };
pages += 1;and have page.tsx / tasks-board.tsx read .tasks and show a "showing the first 5,000 open tasks" notice when truncated is set. With that, a 40-page stub stops at 10 calls. Load-more wouldn't fit here because the newest task sorts last.
Optional: a request-generation ref in refetch would stop a slow project-A read from landing under a project-B filter.
|
Thanks @officialasishkumar, merged. The Tasks board now shows every open task instead of stopping at 100. |
By opening this pull request you agree to the Contributor License Agreement. On your first pull request a bot asks you to sign it with a one-line comment.
Fixes #294
GET /api/tasksstopped at 100 tasks in board order (column position, then newest first), and the board asked for all tasks in one request. A new task gets the highest position, so once a workspace had more than 100 tasks (archived ones included), the newest task disappeared after a reload and the column counts were short.What changed
GET /api/taskspages (backend/src/tasks/)cursorandexclude_archived=1. The response now carrieshas_moreandnext_cursornext totasks.limitis unchanged (default 100, held between 1 and 500).next_cursorback ascursor, with the same other query, for the next page. Without a cursor the first page is the same as before, so the agent's tools and other callers see no change.listTaskPageForOrginrepo.tsreads one page after the cursor, plus one row to know whether another page follows.listTasksForOrg, which the gateway'stask_listtool uses, now sits on top of it with the same signature and result.page-cursor.ts) is the last task's full sort key:order_key,created_atas whole microseconds since the epoch, andid, as base64url JSON. Microseconds come from Postgres (extract(epoch …)) and go back as'epoch' + n microseconds, the way the thread relationships cursor does it, so tasks created within one millisecond are neither repeated nor skipped.order_keysorts up and the rest down, so "after the cursor" isorder_key > k or (order_key = k and (created_at, id) < (c, i)).400 {"error":"cursor is invalid"}before any query. The query stays scoped to the caller's workspace.exclude_archived=1leaves archived tasks out in the query, so they never take a place on a page of the board.The board (
frontend/app/(library)/tasks/tasks-api.ts)fetchTasksasks for pages of 500 withexclude_archived=1and followsnext_cursorto the end. The board and its column counts then hold every open task. Archived tasks have no column, and the board already dropped them.Docs: the
GET /api/tasksrow indocs-site/docs/api/skills.mdx.Across a release: an old board ignores the new fields. A new board talking to an old backend gets no
next_cursorand reads one page, as it does today.Tests
backend/src/tasks/repo.test.ts(the test inbackend/src/tasksthe issue asks for), against the real database:listTasksForOrgstill answers its first 100.backend/src/tasks/page-cursor.test.ts: a round trip with fractional and negative positions, and 13 malformed cursors refused.backend/test/tasks.test.ts, through the route:has_more: trueand a cursor; page two has the last 3 andhas_more: false,next_cursor: nullexclude_archived=1, the first page starts after the archived tasks, holds none, and the newest task comes on the next pagefrontend/app/(library)/tasks/tasks-api.test.ts, over a stubbed fetcher: two pages read to the end (501 tasks) with the exact request paths, every page scoped to the chosen project, a missing cursor read as the last page, a 503 on page two failing the read, a task returned on two pages shown once, and a repeated cursor stopping the loop.Checks with Bun 1.3.14, backend tests on
pgvector/pgvector:0.8.6-pg16-bookworm:bun run typecheck(root): passescd backend && bun run test: 3634 pass, 0 fail, then the Slack suite 119 pass, 0 failcd frontend && bun run test: 1985 pass, 0 failcd frontend && bun run lint: 248 warnings and 22 infos, the same asmaincd frontend && bun run build: passescd docs-site && bunx blume validate: no broken linksbun test scripts/agent-docs.test.ts: 5 passEnd to end
I ran a real backend on its own Postgres and a production build of the frontend (
next start), signed in, and created tasks throughPOST /api/tasks: 3 archived first, then 104 spread over the three columns, then "Newest task". Open tasks: 57 to do, 28 in progress, 20 done.GET /api/tasks?scope=all, answers 100 tasks, 3 of them archived, without "Newest task" (and now sayshas_more: true)./tasksin the browser shows Todo 57, In progress 28, Done 20, with "Newest task" on the board and no archived task. It is still there after a reload.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.